<template>
	<view class="course-content">
		<view class="notdata-box" v-if="courseList.length == 0">
			<image src="../../static/index/not-data.png" mode=""></image>
			<view>还没有数据咯</view>
		</view>
		<scroll-view scroll-y class="course-box" v-else>
			<!--  -->
			<view class="course-item" v-for="(item,index) in courseList" :key="index" @click="gotoDetail(item.excellent_course_id)">
				<view class="item-img">
					<image :src="item.full_cover" mode="aspectFill"></image>
				</view>
				<view class="item-detail">
					<view class="item-title">{{item.title}}</view>
					<view class="item-bottom">
						<view>￥{{item.price}}</view>
						<!-- <u-button type="success" :custom-style="customStyle" size='mini'>立即抢购</u-button> -->
					</view>
				</view>
			</view>
			<!--  -->
			<view class="course-item" v-for="(item,index) in courseListv" :key="index" @click="gotoDetailv(item.live_course.id)">
				<view class="item-img">
					<image :src="item.full_cover" mode="aspectFill"></image>
				</view>
				<view class="item-detail">
					<view class="item-title">{{item.title}}</view>
					<view class="item-bottom">
						<view>￥{{item.price}}</view>
						<!-- <u-button type="success" :custom-style="customStyle" size='mini'>立即抢购</u-button> -->
					</view>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import { getPurchasedCourses,getCourseOrders,getVideoCourse } from '@/api/index.js'

	export default {
		data() {
			return {
				courseList: [],
				courseListv: [],
				customStyle: {
					backgroundColor: '#2AC092',
					color: "#fff",
					fontSize: '30rpx',
					padding: '15rpx'
				}
			}
		},
		mounted() {
			this.getPurchasedCourses()
			// this.getVideoCourse()
			this.getCourseOrders()
		},
		methods:{
			gotoDetail(id){
				// 已购课程跳转
				uni.navigateTo({
					url:'/pagesA/courseDetail/index?type=1' + '&ids=' + id
				})
			},
			gotoDetailv(id){
				// 已购课程跳转
				uni.navigateTo({
					url:'/pagesA/courseDetail/index?type=2' + '&ids=' + id
				})
			},
			// 视频
			getVideoCourse() {
				getVideoCourse().then(res=>{
					console.log(6,res);
				})
			},
			// 直播课程
			getCourseOrders() {
				let that = this;
				getCourseOrders().then(res=>{
					// console.log(53,res);
					that.courseListv = res.data.data;
				})
			},
			// 已购课程list
			getPurchasedCourses(){
				let that = this;
				getPurchasedCourses().then(res=>{
					// console.log(888,res.data.data);
					that.courseList = res.data.data;
				}).catch()
			}
		}
	}
</script>

<style lang="scss">
	.notdata-box {
		display: flex;
		flex-direction: column;
		align-items: center;
		color: #B2B3B8;
		font-size: 28rpx;
		height: 60vh;
		justify-content: center;

		>image {
			width: 410rpx;
			height: 240rpx;
		}
	}

	.course-box {
		height: 100vh;

		.course-item {
			display: flex;
			background-color: #fff;
			border-radius: 5px;
			padding: 10px;
			margin: 0 auto;
			margin-top: 10px;
			width: 95%;
		}


		.item-img {
			width: 350rpx;
			height: 175rpx;
			border-radius: 10rpx;
			margin-right: 10rpx;

			>image {
				width: 100%;
				height: 100%;
				border-radius: 10rpx;
			}
		}

		.item-detail {
			display: flex;
			justify-content: space-between;
			flex-direction: column;

			.item-title {
				font-size: 30rpx;
				font-family: Source Han Sans CN;
			}

			.item-bottom {
				display: flex;
				justify-content: space-between;
				align-items: flex-end;
				font-size: 36rpx;

				>view {
					color: #FF6D6A;
				}
			}
		}
	}
</style>